<?php

namespace app\admin\controller\print_md;

use app\data\model\DataExpress;
use think\admin\Controller;
use think\admin\helper\QueryHelper;

class Express extends Controller
{
    public function index(){
        DataExpress::mQuery()->where(['del'=>0])->layTable(function () {
            $this->title = '快递公司管理';
        }, function (QueryHelper $query) {

        });
    }

    /**
     * 列表数据处理
     * @param array $data
     */
    protected function _index_page_filter(array &$data)
    {

    }
    public function add(){
        if($this->request->isPost()){
            $post = $this->request->post();
            $this->_vali(['name.require' => '参数不能为空！']);
            $this->_vali(['code.require' => '参数不能为空！']);
            $this->_vali(['code100.require' => '参数不能为空！']);
//            $this->_vali(['partnerId.require' => '商家代码不能为空！']);
//            $this->_vali(['partnerKey.require' => '商家秘钥不能为空！']);
            DataExpress::create(array(
                'name'          => $post['name'],
                'icon'        => $post['icon'],
                'website'   => $post['website']??'',
                'code'       => $post['code'],
                'code100'   => $post['code100'],
                'codebird'   => $post['code100'],
                'partnerId'       => $post['partnerId']??'',
                'partnerKey'       => $post['partnerKey']??''
            ));
            $this->success('添加快递公司成功');
        }
        $this->fetch();
    }
    public function edit(){
        if($this->request->isPost()){
            $post = $this->request->post();
            $this->_vali(['name.require' => '参数不能为空！']);
            $this->_vali(['code.require' => '参数不能为空！']);
            $this->_vali(['code100.require' => '参数不能为空！']);
            $this->_vali(['partnerId.require' => '商家代码不能为空！']);
            $this->_vali(['partnerKey.require' => '商家秘钥不能为空！']);
            $id = $this->request->post('id');
            DataExpress::update(array(
                'name'          => $post['name'],
                'icon'        => $post['icon'],
                'website'   => $post['website']??'',
                'code'       => $post['code']??'',
                'code100'   => $post['code100']??'',
                'codebird'   => $post['code100'],
                'partnerId'       => $post['partnerId'],
                'partnerKey'       => $post['partnerKey']
            ),['id'=>$id]);
            $this->success('编辑快递公司成功');
        }
        $id = $this->request->get('id');
        $info = DataExpress::getDetail('*',['id'=>$id]);
        $this->info = $info;
        $this->id = $id;
        $this->fetch();
    }
    public function del(){
        $id = $this->request->get('id');
        DataExpress::update(array(
                'del'          => 1
            ),['id'=>$id]);
            $this->success('删除快递公司成功');
    }
}
